﻿#include "DANodePalette.h"
//===================================================
// using DA namespace -- 禁止在头文件using！！
//===================================================

using namespace DA;

//===================================================
// DANodePalette
//===================================================
#ifndef DANODEPALETTE_PROPERTY_COLOR_CPP
#define DANODEPALETTE_PROPERTY_COLOR_CPP(Role, RoleName)                                                               \
    const QColor& DANodePalette::get##RoleName() const                                                                 \
    {                                                                                                                  \
        return getColor(Role);                                                                                         \
    }                                                                                                                  \
    const QColor& DANodePalette::getGlobal##RoleName()                                                                 \
    {                                                                                                                  \
        return globalNodePalette->get##RoleName();                                                                     \
    }
#endif
#ifndef DANODEPALETTE_PROPERTY_BRUSH_CPP
#define DANODEPALETTE_PROPERTY_BRUSH_CPP(Role, RoleName)                                                               \
    const QBrush& DANodePalette::get##RoleName() const                                                                 \
    {                                                                                                                  \
        return getBrush(Role);                                                                                         \
    }                                                                                                                  \
    const QBrush& DANodePalette::getGlobal##RoleName()                                                                 \
    {                                                                                                                  \
        return globalNodePalette->get##RoleName();                                                                     \
    }
#endif
DANODEPALETTE_PROPERTY_COLOR_CPP(RoleTextColor, TextColor)
DANODEPALETTE_PROPERTY_COLOR_CPP(RoleBorderColor, BorderColor)
DANODEPALETTE_PROPERTY_COLOR_CPP(RoleLinkLineColor, LinkLineColor)
DANODEPALETTE_PROPERTY_COLOR_CPP(RoleLinkPointBorderColor, LinkPointBorderColor)

DANODEPALETTE_PROPERTY_BRUSH_CPP(RoleBackgroundBrush, BackgroundBrush)
DANODEPALETTE_PROPERTY_BRUSH_CPP(RoleLinkPointBrush, LinkPointBrush)

DANodePalette::DANodePalette()
{
    m_colors                          //颜色初始化
            << QColor(0, 0, 0)        // RoleText
            << QColor(128, 128, 147)  // RoleBorderColor
            << QColor(128, 128, 147)  // RoleLinkLine
            << QColor(128, 128, 147)  // RoleLinkPointBorderColor
            ;
    m_brushs << QBrush(QColor(255, 255, 255))  // RoleBackgroundBrush
             << QBrush(QColor(32, 128, 240))   // RoleLinkPointBrush
            ;
}

const DANodePalette& DANodePalette::getGlobalPalette()
{
    return (*globalNodePalette);
}

void DANodePalette::setGlobalPalette(const DANodePalette& pl)
{
    *globalNodePalette = pl;
}

QColor& DANodePalette::color(ColorRole r)
{
    return (m_colors[ int(r) ]);
}

const QColor& DANodePalette::getColor(DANodePalette::ColorRole r) const
{
    return (m_colors[ int(r) ]);
}

const QColor& DANodePalette::getGlobalColor(DANodePalette::ColorRole r)
{
    return (globalNodePalette->getColor(r));
}

QBrush& DANodePalette::brush(BrushRole r)
{
    return (m_brushs[ int(r) ]);
}

const QBrush& DANodePalette::getBrush(BrushRole r) const
{
    return (m_brushs[ int(r) ]);
}
/**
 * @brief DANodePalette::getGlobalBrush
 * @param r
 * @return
 */
const QBrush& DANodePalette::getGlobalBrush(BrushRole r)
{
    return (globalNodePalette->getBrush(r));
}
